package com.hj.system.utils;

import java.util.HashMap;
import java.util.Map;

public class ResponseUtil extends HashMap<String, Object> {
    private static final Long serialVersionUID = 1L;

    public ResponseUtil() {
        put("code", 0);
        put("msg", "操作成功");
    }

    public static ResponseUtil error() {
        return error(1, "操作失败");
    }

    public static ResponseUtil error(String msg) {
        return error(500, msg);
    }

    public static ResponseUtil error(int code, String msg) {
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.put("code", code);
        responseUtil.put("msg", msg);
        return responseUtil;
    }

    public static ResponseUtil ok(Object msg) {
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.put("msg", msg);
        return responseUtil;
    }

    public static ResponseUtil ok(Map<String, Object> map) {
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.putAll(map);
        return responseUtil;
    }

    public static ResponseUtil ok() {
        return new ResponseUtil();
    }

    public static ResponseUtil okContent(Object conetent) {
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.put("content", conetent);
        return responseUtil;
    }

    public static ResponseUtil error(int code, String msg, Object conetent) {
        ResponseUtil responseUtil = error(code, msg);
        responseUtil.put("content", conetent);
        return responseUtil;
    }

    @Override
    public ResponseUtil put(String key, Object value) {
        super.put(key, value);
        return this;
    }
    public Object getContent(){
        return get("content");
    }
}
